package com.leng.Context;

import com.github.pagehelper.PageInfo;
import com.leng.entity.AccessControlDevice;
import com.leng.service.AccessControlDeviceService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @Author: 冷俊杰
 * @Description: TODO
 * @DateTime: 2022/7/18 14:56
 **/
@Controller
public class AccessControlDeviceContext {
    @Resource
    private AccessControlDeviceService as;

    /*查询所有的设备信息*/
    @RequestMapping("/listAccess")
    public ModelAndView listAccessControlDevice(@RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", required = false, defaultValue = "3") int pageSize) {
        ModelAndView modelAndView = new ModelAndView();
        PageInfo<AccessControlDevice> pageInfo = as.pageInfo(pageNum, pageSize);
        modelAndView.addObject("pageInfo", pageInfo);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    /*删除*/
    @RequestMapping("/deleteAccess")
    public ModelAndView deleteAccessControlDevice(int id, @RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", required = false, defaultValue = "3") int pageSize) {
        ModelAndView modelAndView = new ModelAndView();
        as.deleteAccessControlDevice(id);
        PageInfo<AccessControlDevice> pageInfo = as.pageInfo(pageNum, pageSize);
        modelAndView.addObject("pageInfo", pageInfo);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    /*跳转到添加页面*/
    @RequestMapping("/addjsp")
    public String addjsp() {
        return "add";
    }

    /*添加所有*/
    @RequestMapping("/addAccess")
    public ModelAndView addAccessControlDevice(AccessControlDevice ad, @RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", required = false, defaultValue = "3") int pageSize) {
        ModelAndView modelAndView = new ModelAndView();
        as.addAccessControlDevice(ad);
        PageInfo<AccessControlDevice> pageInfo = as.pageInfo(pageNum, pageSize);
        modelAndView.addObject("pageInfo", pageInfo);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    /*修改状态*/
    @RequestMapping("/updateAccess")
    public ModelAndView updateAccessControlDevice(AccessControlDevice ad, @RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", required = false, defaultValue = "3") int pageSize){
        ModelAndView modelAndView = new ModelAndView();
        as.updateAccessControlDevice(ad);
        PageInfo<AccessControlDevice> pageInfo = as.pageInfo(pageNum, pageSize);
        modelAndView.addObject("pageInfo", pageInfo);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
